import java.util.ArrayList;


public class Sender extends Thread{
	private ArrayList<User> users;
	private MrMonitor mon;
	
	
	public Sender(MrMonitor mon) {
		users = new ArrayList<User>();
		this.mon = mon;
	}
	
	public void run() {
		while(true) {
			String message = mon.getMessage();
			synchronized(this) {
				for(int i = 0; i < users.size(); i++) {
					users.get(i).sendMessage(message);
				}				
			}
		}
	}
	
	public synchronized void removeUser(User u) {
		users.remove(u);
	}
	
	public synchronized void addUser(User u) {
		users.add(u);
	}
}
